<?php

$contract = displayLoanContract($_SESSION['app_id']);

	$contractFile = '';
if($contract !== false)
{
	//echo '<pre>';
	
	$contractFile = $contract['FilePath'];
	
	
}

function getPaymentRegular($pr)
{
	if($pr == 7)
	{
		return 'Weekly';
	}
	else if($pr == 14)
	{
		return 'Fortnightly';
	}
	else if($pr == 30)
	{
		return 'Monthly';
	}
	else
	{
		return;
	}
}

?>

<img src="images/money-sign.gif" />
<h2><i class="fa fa-arrow-circle-right"></i>Final step! Confirm your loan.</h2>
<p class="money">Complete this final step to confirm your loan and get paid.</p>
<div class="well">
  <h2><i class="fa fa-arrow-circle-right"></i>Important - Action Required</h2>
  <div class="agree">
    <p ><strong>Scroll to the bottom of the page to confirm your loan.</strong></p>
    <p>If you have any questions, <a href="http://maxcash.com.au/contact.html" target="_blank">contact us</a> and we'll help you through it. &nbsp;<img src="images/loanConfirm.png" style="margin-left:20px;"></p>
  </div>
</div>
<h2><i class="fa fa-arrow-circle-right"></i>Loan Contract</h2>
<p>Max Finance Pty Ltd ACN 166 569 311 Australian Credit License Number 450312 ("Lender / us / we&quot;) offers you a loan on the amount specified in the Financial Table and on the terms and conditions set out in this contract.</p>
<div class="well" >
  <h4 class="financetable">Financial Table</h4>
  <p class="text-center">Contract prepared as at
    <?php if(isset($contract['CreatedDate'])) echo date('d F, Y', strtotime($contract['CreatedDate'])); //date('d F, Y'); ?>
  </p>
  <div class="payment">
    <p class="cont-prepared"> The borrower's details: <strong>Name:</strong>
      <?php if(isset($contract['FirstName'])) echo $contract['FirstName']; ?>
      | <strong>Address:</strong>
      <?php 
	if(isset($contract['StreetNo'])) 
		$address_array[] = $contract['StreetNo'];
		
	if(isset($contract['Street'])) 
		$address_array[] = $contract['Street'];
		
	if(isset($contract['Suburb'])) 		
		$address_array[] = $contract['Suburb'];
		
	if(isset($contract['State'])) 		
		$address_array[] = $contract['State'];
		
	if(isset($contract['PostCode'])) 		
		$address_array[] = $contract['PostCode'];
	
	array_filter($address_array);
	$address = implode(', ',$address_array);		
	echo $address;
		
		?>
      | <br />
      <strong>Telephone:</strong>
      <?php if(isset($contract['Telephone'])) echo $contract['Mobile'];
	else if (isset($contract['HomePhone'])) echo $contract['HomePhone']; ?>
      | <strong>Email:</strong>
      <?php if(isset($contract['Email'])) echo $contract['Email'];  ?>
    </p>
    <h4  class="line">Repayment Schedule</h4>
    <table width="100%" border="1" style="border-collapse:collapse" class="table table-bordered" >
      <tr>
        <td scope="col">Cash to you</td>
        <td scope="col"><!--$1000-->
          $
          <?php if(isset($contract['LoanAmount'])) echo $contract['LoanAmount'];?></td>
      </tr>
      <tr>
        <td>Repayment</td>
        <td><!--$125-->
          $
          <?php if(isset($contract['PaymentRegular'])) echo $contract['PaymentRegular']; if(isset($contract['RepaymentBy'])) echo ' ( '. getPaymentRegular($contract['RepaymentBy']).' )';?></td>
      </tr>
      <tr>
        <td>First Direct Debit Date</td>
        <td><!--01-Jan-2014-->
          <?php if(isset($contract['firstPaymentDate'])) echo date('d F, Y', strtotime($contract['firstPaymentDate']));?></td>
      </tr>
      <tr>
        <td height="23">Last Direct Debit Date</td>
        <td><!--24-Feb-2014-->
          <?php if(isset($contract['LastPaymentDate'])) echo date('d F, Y', strtotime($contract['LastPaymentDate']));?></td>
      </tr>
    </table>
    <div class="contract"></div>
    <h4 class="line">Credit Fees and Charges</h4>
    <p>The following fees and Charges for your loan will be incurrect at the date specified above.the amount becomes<br />
      due and will be debited from your account upon the date. </p>
    <p>By agreeing to this contract, you authorise the payment of your loan as follow:</p>
    <ul class="principal">
      <li>Establishment fees:<strong class="fees">$
        <?php if(isset($contract['LoanAmount'])) echo $contract['LoanAmount']*0.2;?>
        </strong></li>
      <li>(20% of principal)</li>
    </ul>
    <ul class="principal">
      <li>Monthly Credit fee:<strong class="credit">$
        <?php if(isset($contract['LoanAmount'])) echo $contract['LoanAmount']*0.04;?>
        </strong></li>
      <li class="per-month">(4% of principal per month)</li>
    </ul>
    <ul class="principal">
      <li class="payable">Principal amount payable to you:<strong class="payment">$
        <?php if(isset($contract['LoanAmount'])) echo $contract['LoanAmount'];?>
        </strong></li>
    </ul>
    <ul class="principal">
      <li class="total-credit">Total amount of credit:<strong class="amt-loan">$
        <?php if(isset($contract['LoanAmount'])) echo $contract['LoanAmount']*1.24;?>
        </strong></li> 
    </ul>
    <div class="contract"></div>
    <h4 class="line">Charges that may be payable</h4>
    <div class="row-fluid ">
      <div class="span3">Payment Dishonour Fee:</div>
      <div class="span9">
        <p>$35.00 each time a direct debit or other payment is not made in full or at <span class="schedule">a time a repayment is rescheduled forward at your request. This fee </span><span class="internal">includes our internal administrative costs and external third party costs.</span></p>
      </div>
    </div>
    <div class="row-fluid ">
      <div class="span3">Default fee:</div>
      <div class="span9">
        <p><span class="inter">$7.00 per day to cover costs of administratering your account while it is </span><span class="inter-cost">in arrears.</span></p>
      </div>
    </div>
  </div>
  <a href="index.php?requestmoney" class="button btnSmlGoldArrow tracked-link smt" id="linkGetMoney"></a>
  <?php
$targetDir = realpath(dirname(__DIR__)).'\MC_DATA'; // Relative to the root

$targetFolder = str_replace('\\', '/', $targetDir); 

$req_type = explode('/',$_SERVER['SERVER_PROTOCOL']);
$server = $_SERVER['HTTP_HOST'];
$url = strtolower($req_type[0]).'://'.$server;
//echo '<pre>'; print_r($_SERVER); //exit;
if($_SERVER['SERVER_NAME'] == 'localhost')
{
	$url = strtolower($req_type[0]).'://'.$server;
}
$root = explode('/',$_SERVER['PHP_SELF']);
if(in_array('account', $root))
{
	$flag = true;
	foreach($root as $str)
	{
		if($str == 'account')
		{
			$flag = false;
		}
		
		if($flag)
		{
			$url .= $str.'/';
		}
	}
}


 
?>
</div>
<script type="text/javascript">  
  
  	window.onresize =  function(){
			resizeIframe();
		}	
	
	
	function resizeIframe(){
		$('#scFrame').contents().find('.container').css({
		 "padding":"0px",
		  //"width":"100%"
		});
		
		$('#scFrame').contents().find('.bodycontainer').css({
		 "padding":"10px"
		});
		var windowWidth = $('#scFrame').contents().width()+50;
		
			var iframeWidth = $('#scFrame').width() ;
			var widthRatio = iframeWidth/windowWidth;
			var widthRatio = (iframeWidth/windowWidth); 
			
			//alert(iframeWidth+"/"+windowWidth+" = "+ widthRatio); 
	
		$('#scFrame').contents().find('html').css({
													  
			
			   "transform":"scale("+widthRatio+")", 
			   "transform-origin":"0 0",
			   "padding":"0px"
		});
		
	}
   $(window).load(function() {
						   
		
	resizeIframe();
		   
					   
	});
    </script>
    <div style="overflow:auto;-webkit-overflow-scrolling:touch">
 

<iframe id="scFrame" frameborder="0" width="100%" height="426" src="<?php echo $url.'MC_DATA/Contract/'.$contractFile;  ?>"  ></iframe>
</div> 
<!--<iframe id="scFrame" src="<?php echo $url.'MC_DATA/Contract/'.$contractFile;  ?>" width="100%" style="max-width:630px;max-height:400px" align="middle" ></iframe>-->
<p style="padding-top:20px; text-align:center; cursor: pointer;">
<a href="<?php echo $url.'MC_DATA/Contract/'.$contractFile; ?>" role="button" class="btn btn-grey" id="Contract" target="_blank">View Contract</a></p>

<h4 class="line">Confirm Loan</h4>
<form action="<?php //echo $_SERVER['PHP_SELF']; ?>?dashboard" method="post">
  <p>
    <input type="checkbox" name="signing" value="yes" id="signing" class="required"  />
    &nbsp;I confirm that i have read,understoodd,and accepted the loan contract.</p>
  <a href="#" role="button" class="btn btn-green  btn-large " id="agree" >I Agree the Terms and Conditions</a>
  <button class="disabled_btn">Cancel</button>
</form>
</div>

<div class="modal hide fade" id="eSignModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">  
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Please Sign - Signature mush match your driver licence</h4>
      </div>
      <div class="modal-body signpad"  style="max-height:390px;">
        <iframe src="e-signature-060514.php" style="width:100%;height:500px;border:0px"></iframe>
      </div>
      <div class="modal-footer"> </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<script>
  $(document).ready(function(){
	//$('#myModal').modal('show')
	
	$('#agree').on('click', function(){
	var isChecked = $('#signing').prop('checked');
		
	if(isChecked != false)
	{
		$('#eSignModal').modal('show');
		return false;
	}
	else
	{
		alert('please agree term');
		return false;
	}
	});
	
	});
  </script>
